<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <title>查看帖子</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/all.min.css">
    <style>
        .container {
            padding: 20px;
            max-width: 1000px;
            margin: 0 auto;
        }
        .post-header {
            margin-bottom: 20px;
            padding-bottom: 20px;
            border-bottom: 1px solid #e7eaec;
        }
        .post-title {
            font-size: 24px;
            margin-bottom: 10px;
        }
        .post-info {
            color: #666;
            font-size: 14px;
        }
        .post-info span {
            margin-right: 15px;
        }
        .post-content {
            margin-bottom: 30px;
            line-height: 1.6;
        }
        .post-type {
            padding: 3px 8px;
            border-radius: 3px;
            font-size: 12px;
            color: white;
            margin-right: 10px;
        }
        .type-1 { background-color: #1ab394; }
        .type-2 { background-color: #f8ac59; }
        .type-3 { background-color: #23c6c8; }
        .replies {
            margin-top: 30px;
        }
        .reply-item {
            padding: 15px;
            border-bottom: 1px solid #e7eaec;
        }
        .reply-header {
            margin-bottom: 10px;
            color: #666;
            font-size: 14px;
        }
        .reply-content {
            margin-bottom: 10px;
        }
        .reply-form {
            margin-top: 30px;
            padding: 20px;
            background-color: #f9f9f9;
            border-radius: 4px;
        }
        .reply-form textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 10px;
            min-height: 100px;
            resize: vertical;
        }
        .btn {
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            color: white;
        }
        .btn-primary {
            background-color: #1ab394;
        }
        .btn-primary:hover {
            background-color: #18a689;
        }
        .btn-default {
            background-color: #f3f3f4;
            color: #333;
        }
        .btn-default:hover {
            background-color: #e7eaec;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="post-header">
        <h1 class="post-title">
                <span class="post-type type-${post.postType}">
                    <c:choose>
                        <c:when test="${post.postType == 1}">学生帖子</c:when>
                        <c:when test="${post.postType == 2}">心理咨询</c:when>
                        <c:when test="${post.postType == 3}">就业指导</c:when>
                    </c:choose>
                </span>
            ${post.title}
        </h1>
        <div class="post-info">
            <span><i class="fas fa-user"></i> ${post.username}</span>
            <span><i class="fas fa-eye"></i> 浏览 ${post.viewCount}</span>
            <span><i class="fas fa-clock"></i> <fmt:formatDate value="${post.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></span>
        </div>
    </div>

    <div class="post-content">
        ${post.content}
    </div>

    <div class="replies">
        <h3><i class="fas fa-comments"></i> 回复列表</h3>
        <c:forEach items="${replyList}" var="reply">
            <div class="reply-item">
                <div class="reply-header">
                    <span><i class="fas fa-user"></i> ${reply.username}</span>
                    <span><i class="fas fa-clock"></i> <fmt:formatDate value="${reply.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></span>
                </div>
                <div class="reply-content">
                        ${reply.content}
                </div>
            </div>
        </c:forEach>
    </div>

    <div class="reply-form">
        <h3><i class="fas fa-reply"></i> 发表回复</h3>
        <form id="replyForm">
            <textarea id="replyContent" name="content" placeholder="请输入回复内容..." required></textarea>
            <div>
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-paper-plane"></i> 提交回复
                </button>
                <button type="button" class="btn btn-default" onclick="history.back()">
                    <i class="fas fa-arrow-left"></i> 返回
                </button>
            </div>
        </form>
    </div>
</div>

<script>
    document.getElementById('replyForm').onsubmit = function(e) {
        e.preventDefault();

        const content = document.getElementById('replyContent').value.trim();
        if (!content) {
            alert('请输入回复内容');
            return;
        }

        const formData = new FormData();
        formData.append('postId', '${post.postId}');
        formData.append('content', content);

        fetch('${pageContext.request.contextPath}/admin/post/reply', {
            method: 'POST',
            body: new URLSearchParams(formData)
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('回复成功');
                    location.reload();
                } else {
                    alert(data.message || '回复失败');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('回复失败');
            });
    };
</script>
</body>
</html> 